package plus.easydo.starter.file.minio.config;

import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import plus.easydo.starter.file.minio.MinioTemplate;
import plus.easydo.starter.file.minio.MinioFileStoreServer;


/**
 * minio自动装配
 * @author laoyu
 * @version 1.0
 */
@Configuration
@EnableConfigurationProperties(MinioProperties.class)
public class MinioAutoConfiguration {

    @Autowired
    private MinioProperties minioProperties;


    /**
     * 初始化minio
     *
     * @return io.minio.MinioClient
     * @author laoyu
     * @throws InvalidPortException ipe
     * @throws InvalidEndpointException iee
     */
    @Bean
    public MinioClient minioClient() throws InvalidPortException, InvalidEndpointException {
        return new MinioClient( minioProperties.getServerAddress(), minioProperties.getAccessKey(), minioProperties.getSecretKey());
    }

    @Bean
    public MinioTemplate minioTemplate(){
        return new MinioTemplate();
    }

    @Bean
    public MinioFileStoreServer fileStoreService(){
        return new MinioFileStoreServer();
    }
}
